// import './assets/main.css'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import store from './store'  // 确保路径正确
import axios from 'axios'
import { createStore } from 'vuex'

const app = createApp(App)

// 必须在 app.use(store) 之前初始化
const initializeAuth = () => {
  const authData = localStorage.getItem('auth')
  if (authData) {
    try {
      const { user, token } = JSON.parse(authData)
      store.commit('SET_AUTH', { user, token })
      axios.defaults.headers.common['Authorization'] = `Bearer ${token}`
    } catch (error) {
      console.error('Auth data parsing failed:', error)
    }
  }
}

initializeAuth()

app.use(store)
app.use(router)
app.use(ElementPlus)

app.mount('#app')

console.log('Vue app mounted:', {
  store: app.config.globalProperties.$store,
  router: app.config.globalProperties.$router
})